package com.ruoyi.candidate.service.impl;

import com.ruoyi.candidate.domain.Candidate;
import com.ruoyi.candidate.mapper.CandidateMapper;
import com.ruoyi.candidate.service.ICandidateService;
import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CandidateServiceImpl implements ICandidateService {

    @Autowired
    private CandidateMapper candidateMapper;

    @Override
    public int register(Candidate candidate) {
        return candidateMapper.insertCandidate(candidate);
    }

    @Override
    public Candidate login(String idNumber, String password) {
        Candidate candidate = candidateMapper.selectCandidateForLogin(idNumber, password);
        if (candidate == null) {
            throw new RuntimeException("身份证号或密码不正确");
        }
        return candidate;
    }

    @Override
    public int modifyPassword(String idNumber, String phone, String newPassword) {
        Candidate candidate = candidateMapper.selectCandidateByIdNumber(idNumber);
        if (candidate == null || !candidate.getPhone().equals(phone)) {
            throw new RuntimeException("身份证号或电话号码不匹配");
        }
        return candidateMapper.updatePassword(idNumber, phone, newPassword);
    }

    @Override
    public int updateRegistrationInfo(Candidate candidate) {
        return candidateMapper.updateRegistrationInfo(candidate);
    }

    @Override
    public int updateBasicInfo(Candidate candidate) {
        return candidateMapper.updateBasicInfo(candidate);
    }

    @Override
    public int updateNotificationInfo(Candidate candidate) {
        return candidateMapper.updateNotificationInfo(candidate);
    }

    @Override
    public int deleteCandidateById(Long id) {
        return candidateMapper.deleteCandidateById(id);
    }

    @Override
    public Candidate getCandidateByIdNumber(String idNumber) {
        return candidateMapper.selectCandidateByIdNumber(idNumber);
    }

    @Override
    public Candidate getCandidateById(Long id) {
        return candidateMapper.selectCandidateById(id);
    }

    @Override
    public Candidate getBaseInfoById(Long id){ return candidateMapper.selectBaseInfoById(id); }
}
